//获取章节信息

import axios from "axios";
import { ElMessage } from "element-plus";
import { ref } from "vue";
import { getCurrentInstance } from "vue";

export async function getChapterContent(id, chapterID,proxy) {
  console.log(id, chapterID);
  try {
    const response = await proxy.$http.get("/api/book/chapter", {
      params: { book_id: id,chapter_index: chapterID },
    });
    const chapter = response.data.data;
    console.log(response.data);
    const isSuccess = response.data.success;
    const message = response.data.message;
    // console.log(response.data);
    if (isSuccess === false) {
      ElMessage.error(message);
    } else {
      ElMessage.success("获取成功");
      return chapter;
    }
  } catch (error) {
    console.error(`Error fetching ${id} chapter:`, error);
    return [];
  }
}
